package com.hmy.infrastructure.service;

import com.hmy.infrastructure.common.properties.DingTalkProperties;

import javax.annotation.Resource;
import java.net.URI;
import java.net.URISyntaxException;

@Service
public class DingTalkService {

    @Resource
    private RestTemplate restTemplate;

    @Resource
    private DingTalkProperties dingTalkProperties;


    public GetAppTokenResponse getAccessToken() throws URISyntaxException {
        StringBuilder url = new StringBuilder(dingTalkProperties.getAccessTokenUrl());
        url.append("?appkey=").append(dingTalkProperties.getAppKey());
        url.append("&appsecret=").append(dingTalkProperties.getAppSecret());
        URI uri = new URI(url.toString());
        return restTemplate.getForObject(uri, GetAppTokenResponse.class);
    }
}
